﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Security;

namespace Foothill.Service.UserAccount
{
    public class HashUtility : IHashUtility
    {
        public string HashText(string plainText, HashAlgorithm algorithm)
        {
            return FormsAuthentication.HashPasswordForStoringInConfigFile(plainText, GetAlgorithmName(algorithm));
        }

        public string HashText(string text)
        {
            return FormsAuthentication.HashPasswordForStoringInConfigFile(text, GetAlgorithmName(HashAlgorithm.SHA1));
        }

        private string GetAlgorithmName(HashAlgorithm algorithm)
        {
            switch (algorithm)
            {
                case HashAlgorithm.MD5:
                    return "MD5";
                case HashAlgorithm.SHA1:
                    return "SHA1";
            }

            return "SHA1";
        }
    }
}
